<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="pName">
        <el-input
          v-model="queryParams.pName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品类型" prop="pType">
        <el-cascader
          :options="productFormTree"
          :props="{value:'code',label:'name' }"
          clearable
          regionTree
          placeholder="请输入产品类型"
          v-model="queryParams.pType"
          @keyup.enter.native="handleQuery"
        ></el-cascader>
<!--        <el-input-->
<!--          v-model="queryParams.pType"-->
<!--          placeholder="请输入产品类型"-->
<!--          clearable-->
<!--          -->
<!--        />-->
      </el-form-item>
      <el-form-item label="行业" prop="pIndustry">
        <el-select v-model="queryParams.pIndustry" clearable placeholder="请选择行业" clearable>
          <el-option
            v-for="dict in dict.type.product_industry"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="版本型号" prop="pVersion">-->
<!--        <el-input-->
<!--          v-model="queryParams.pVersion"-->
<!--          placeholder="请输入版本型号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="产品介绍" prop="pIntroduce">-->
<!--        <el-input-->
<!--          v-model="queryParams.pIntroduce"-->
<!--          placeholder="请输入产品介绍"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="厂商" prop="pManufacturer">-->
<!--        <el-input-->
<!--          v-model="queryParams.pManufacturer"-->
<!--          placeholder="请输入厂商"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="联系人" prop="pContacts">-->
<!--        <el-input-->
<!--          v-model="queryParams.pContacts"-->
<!--          placeholder="请输入联系人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="联系方式" prop="pTel">-->
<!--        <el-input-->
<!--          v-model="queryParams.pTel"-->
<!--          placeholder="请输入联系方式"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="关键词" prop="pKeyword">-->
<!--        <el-input-->
<!--          v-model="queryParams.pKeyword"-->
<!--          placeholder="请输入关键词"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="数据来源" prop="pDataSource">-->
<!--        <el-input-->
<!--          v-model="queryParams.pDataSource"-->
<!--          placeholder="请输入数据来源"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['info:product:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['info:product:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['info:product:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['info:base:importPage']"
        >批量导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['info:product:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="data" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="产品名称" align="center" prop="pName" />
      <el-table-column label="产品类型" align="center" prop="pType" >
        <template slot-scope="scope">
          <span>{{productFormMap[scope.row.pType]}}</span>
        </template>
      </el-table-column>
      <el-table-column label="行业" align="center" prop="pIndustry">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_industry" :value="scope.row.pIndustry"/>
        </template>
      </el-table-column>
      <el-table-column label="版本型号" align="center" prop="pVersion" />
      <el-table-column label="产品介绍" align="center" prop="pIntroduce" />
      <el-table-column label="厂商" align="center" prop="pManufacturer" />
      <el-table-column label="联系人" align="center" prop="pContacts" />
      <el-table-column label="联系方式" align="center" prop="pTel" />
      <el-table-column label="关键词" align="center" prop="pKeyword" />
      <el-table-column label="数据来源" align="center" prop="pDataSource" />
      <el-table-column label="审核状态" align="center" prop="pStatus" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.pStatus === '0'" type="info">待审核</el-tag>
          <el-tag v-if="scope.row.pStatus === '1'" type="error">不合格</el-tag>
          <el-tag v-if="scope.row.pStatus === '2'" >正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['info:product:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['info:caseInfo:detail']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['info:product:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import ListMixin from "@/minixs/list"
import request from "@/utils/request";
import {listProductType} from "../../../api/info/productType";
export default {
  name: "list",
  dicts:['product_industry'],
  mixins:[ListMixin],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pName: null,
        pType: null,
        pIndustry: null,
        pVersion: null,
        pIntroduce: null,
        pManufacturer: null,
        pContacts: null,
        pTel: null,
        pKeyword: null,
        pDataSource: null,
        pStatus: null,
      },
      productFormMap:{},
      productFormTree:[],
      //   删除地址
      deletedUrl:"/info/product/"
    };
  },
  created() {
    this.getList();
    listProductType(this.queryParams).then(response => {
      const productFormMap = {};
      response.data.forEach(item=>{
        productFormMap[item.levelCode] = item.levelName.replace(",","-")
      })
      this.productFormTree = this.handleTree(response.data, "code", "pcode");
      this.productFormMap = productFormMap;
    });
  },
  methods: {
    handleImport(){
      this.$emit("import-handle", {
        open: true,
        title: "批量导入",
        type:'IMPORT'
      })
    },
    /** 查询产品信息列表 */
    getList() {
      const queryParams = JSON.parse(JSON.stringify(this.queryParams))
      queryParams.pType = queryParams.pType?queryParams.pType.join(","):queryParams.pType;
      this.loading = true;
      request({
        url: '/info/product/list',
        method: 'get',
        params: queryParams
      }).then(response => {
        this.data = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = JSON.parse(JSON.stringify(this.queryParams))
      queryParams.pType = queryParams.pType?queryParams.pType.join(","):queryParams.pType;
      this.download('/info/product/export', {
        ...queryParams
      }, `product_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
